package com.mvc.base.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.extremecomponents.table.limit.Limit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mvc.base.model.BaseGroup;
import com.mvc.base.model.Customer;
import com.mvc.base.service.CustomerManager;
import com.mvc.framework.dao.PropertyFilter;
import com.mvc.framework.service.PageManager;
import com.mvc.framework.util.FrameworkContextUtils;
import com.mvc.framework.util.PageSearch;
import com.mvc.framework.util.PageUtils;

@Controller
@RequestMapping("customer")
public class CustomerController extends BaseGroupController<Customer> {

	@Autowired
	private CustomerManager	customerManager;

	public String select(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Limit limit = PageUtils.getLimit(request);
		PageSearch page = preparePage(request, limit);
		page.getFilters().add(new PropertyFilter("EQI_status", BaseGroup.STATUS_VALID + ""));
		String action = request.getParameter("action");
		if (action != null && action.equals("my")) {
			page.getFilters().add(new PropertyFilter("EQI_userId", FrameworkContextUtils.getCurrentUserId() + ""));
		}
		handlePage(request, page);
		afterPage(request, page, IS_NOT_BACK);
		request.setAttribute("action", "select");
		return getFileBasePath() + "select" + getActualArgumentType().getSimpleName();
	}

	@Override
	public PageManager<Customer> getEntityManager() {
		return customerManager;
	}

	@Override
	public String getFileBasePath() {
		return "base/";
	}

}
